package com.wsoft.form.enums;

import lombok.Getter;
import org.springframework.lang.Nullable;

import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.Map;

/**
 * @author z001
 * @Date 2024/10/25 15:56
 */
@Getter
public enum FieldKindEnum {

    /**
     * VARCHAR
     */
    VARCHAR(1, "字符","254","varchar"),

    /**
     * TEXT
     */
    TEXT(2, "大文本","","text"),

    /**
     * INTEGER
     */
    INTEGER(3, "整数","10","int"),

    /**
     * DECIMAL
     */
    DECIMAL(4, "小数","10,2","decimal"),

    /**
     * DATE
     */
    DATE(5, "日期","yyyy-MM-dd","date"),

    /**
     * DATETIME
     */
    DATETIME(6, "时间","yyyy-MM-dd HH:mm:ss","datetime"),

    /**
     * FILE_PIC
     */
    FILE_PIC(7, "文件:图片","","text"),

    /**
     * FILE_FIlE
     */
    FILE_FILE(8, "文件:附件","","text"),


    /**
     * NOW_TIME
     */
    NOW_TIME(9, "当前时间","yyyy-MM-dd HH:mm:ss","varchar"),

    /**
     * USER
     */
    USER(10, "当前用户","32","varchar"),

    /**
     * ORGANIZATION
     */
    ORGANIZATION(11, "当前组织","32","varchar"),

    /**
     * POST
     */
    POST(12, "当前岗位","32","varchar"),

    /**
     * LEVEL
     */
    LEVEL(13, "当前职级","32","varchar"),

    /**
     * SELECT_USER
     */
    SELECT_USER(14, "选择人员","512","varchar"),

    /**
     * SELECT_ORGANIZATION
     */
    SELECT_ORGANIZATION(15, "选择组织","512","varchar"),

    /**
     * SELECT_POST
     */
    SELECT_POST(16, "选择岗位","512","varchar"),

    /**
     * SELECT_LEVEL
     */
    SELECT_LEVEL(17, "选择职务级别","512","varchar"),

    /**
     * SELECT_FORM
     */
    SELECT_FORM(18, "选择表单","512","varchar"),

    /**
     * DICT
     */
    DICT(19, "字典","512","varchar"),
    /**
     * ENUM
     */
    ENUM(20, "枚举","512","varchar"),
    /**
     * FORMULA
     */
    FORMULA(21, "公式","512","varchar"),

    /**
     * 环境变量
     */
    ENVIRONMENT(22,"环境变量","512","varchar"),

    /**
     * 自定义编码
     */
    CODE(23,"自定义编码","32","varchar")

    ;

    private final Integer fieldKind;

    private final String desc;

    /**
     * 默认值==> 默认长度 或者 默认格式
     */
    private final String value;

    private final String sqlType;

    FieldKindEnum(Integer fieldKind, String desc,String value,String sqlType) {
        this.fieldKind = fieldKind;
        this.desc = desc;
        this.value = value;
        this.sqlType = sqlType;
    }


    private static final Map<Integer, FieldKindEnum> FIELD_KIND_MAPPING = new HashMap<>(16);


    static {
        FieldKindEnum[] var0 = values();
        for (FieldKindEnum item : var0) {
            FIELD_KIND_MAPPING.put(item.getFieldKind(), item);
        }
    }

    @NotNull
    public static FieldKindEnum resolveFieldKind(@Nullable Integer fieldKind) {
        if (null != fieldKind) {
            return FIELD_KIND_MAPPING.get(fieldKind);
        }
        return null;
    }

}
